'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var React = _interopRequireWildcard(_react);

var _antd = require('antd');

var _authCheck = require('../auth-check');

var _authCheck2 = _interopRequireDefault(_authCheck);

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj['default'] = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }

var ConfirmBtn = function (_React$Component) {
    (0, _inherits3['default'])(ConfirmBtn, _React$Component);

    function ConfirmBtn() {
        (0, _classCallCheck3['default'])(this, ConfirmBtn);

        var _this = (0, _possibleConstructorReturn3['default'])(this, (ConfirmBtn.__proto__ || Object.getPrototypeOf(ConfirmBtn)).apply(this, arguments));

        _this.state = {
            visible: false
        };
        _this.handleConfirm = function () {
            var onConfirm = _this.props.onConfirm;

            onConfirm && onConfirm();
            _this.setState({ visible: false });
        };
        _this.getPopBtn = function () {
            var _this$props = _this.props,
                msg = _this$props.msg,
                style = _this$props.style,
                children = _this$props.children;

            return React.createElement(
                _antd.Popconfirm,
                { title: msg, onConfirm: _this.handleConfirm, style: { minWidth: 300 } },
                React.createElement(
                    'a',
                    { style: style },
                    children
                )
            );
        };
        _this.getModalBtn = function () {
            var visible = _this.state.visible;
            var _this$props2 = _this.props,
                msg = _this$props2.msg,
                style = _this$props2.style,
                children = _this$props2.children;

            return React.createElement(
                React.Fragment,
                null,
                React.createElement(
                    _antd.Modal,
                    { title: '\u786E\u8BA4\u64CD\u4F5C', visible: visible, onOk: _this.handleConfirm, onCancel: function onCancel() {
                            return _this.setState({ visible: false });
                        } },
                    React.createElement(
                        'p',
                        null,
                        msg
                    )
                ),
                React.createElement(
                    'a',
                    { style: style, onClick: function onClick() {
                            return _this.setState({ visible: true });
                        } },
                    children
                )
            );
        };
        _this.renderBtn = function () {
            var type = _this.props.type;

            if (type === 'modal') {
                return _this.getModalBtn();
            }
            return _this.getPopBtn();
        };
        return _this;
    }

    (0, _createClass3['default'])(ConfirmBtn, [{
        key: 'render',
        value: function render() {
            var check = this.props.check;

            return React.createElement(
                _authCheck2['default'],
                { check: check },
                this.renderBtn()
            );
        }
    }]);
    return ConfirmBtn;
}(React.Component); /**
                     * 带确认框的文本按钮
                     * @author: ljq
                     * @since: 2019-01-10 18:22:27
                     */


exports['default'] = ConfirmBtn;
module.exports = exports['default'];